﻿using System;

using AMC.SubstitutionCache.Drivers;
using AMC.SubstitutionCache.Services;

namespace AMC.SubstitutionCache.Rendering
{
    public class SubstitutionDriverRenderingInfo : SubstitutionShapeRenderingInfo
    {
        public static readonly Func<dynamic, SubstitutionContext, bool> DefaultLocator = (shape, context) =>
        {
            return shape != null && shape.Metadata.Type == context.ShapeType;
        };

        public SubstitutionDriverRenderingInfo(
            Type contentPartType,
            string shapeType, 
            ISubstitutionDriver driver, 
            string groupId, 
            bool useEditor, 
            Func<dynamic, SubstitutionContext, bool> shapeLocator)
            : base(
                contentPartType, 
                shapeType, 
                groupId)
        {
            UseEditor = useEditor;
            Driver = driver;
            ShapeLocator = shapeLocator ?? DefaultLocator;
        }

        public bool UseEditor { get; private set; }
        public ISubstitutionDriver Driver { get; private set; }
        public Func<dynamic, SubstitutionContext, bool> ShapeLocator { get; private set; }
    }
}